
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

# 构建邮件内容
msg = MIMEText("这是一封测试邮件", "html", "utf-8")
msg["From"] = formataddr(("YZD", "18247165536@163.com"))
msg["to"] = "491254074@qq.com"
msg["Subject"] = "测试邮件"

# 发送邮件
server = smtplib.SMTP_SSL("smtp.163.com")
server.login("18247165536@163.com", "xxxx")  # 发件邮箱地址、授权码
server.sendmail("18247165536@163.com", "491254074@qq.com", msg.as_string())
server.quit()

